package com.example.operation.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.operation.domin.Admin;
import com.example.operation.dto.AdminDto;
import com.example.operation.service.AdminService;
import com.example.operation.utils.Result;
import com.example.operation.vo.AdminVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理员操作模块")
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;


    @ApiOperation(value = "管理员新增接口")
    @PostMapping("/save")
    public Result<String> save(@RequestBody AdminDto adminDto){
        adminService.insertAd(adminDto);
        return Result.ok("管理员新增成功");
    }


    @ApiOperation(value = "管理员修改接口")
    @PutMapping("/update")
    public Integer update(@RequestBody AdminDto adminDto){
        return adminService.updateAd(adminDto);
    }


    @ApiOperation(value = "管理员根据ID查询接口")
    @GetMapping("/selectById")
    public Admin selectById(@RequestParam("id") Integer id){
        return adminService.selectById(id);
    }


    @ApiOperation(value = "管理员分页模糊查询接口")
    @GetMapping("/page")
    public Result<Page<Admin>> page(@RequestParam("pageNumber") @ApiParam(value = "分页页码",required = true) Integer pageNumber,
                                      @RequestParam("pageSize") @ApiParam(value = "分页条数",required = true) Integer pageSize,
                                      @RequestParam(value = "username",required = false) @ApiParam(value = "用户昵称") String username){
        Page<Admin> page = adminService.pageAd(pageNumber,pageSize,username);
        return Result.ok(page);
    }

}
